//处理个人中心页加载文章列表数据逻辑(可查询)
const db = require("../lib/db")

function myArticleList(authorId) {
    return new Promise((resolve, reject) => {
        let sql = `select * from article join author where authorId = '${authorId}'`
        db.querySql(sql).then( data => {
            if (data.length == 0) {
                resolve(400)
            }else{
                let arr = []
                data.map(ele => {
                    arr.push({
                        _id: Buffer.from(String(ele.id)).toString("base64"),
                        title : ele.title, 
                        content: ele.content,
                        desc: ele.desc,
                        imgsrc: ele.imgsrc,
                        time : ele.time,
                        author: ele.author,
                        authorId: ele.authorId,
                        classify : ele.classify,
                        __v: 0
                    })
                })
                console.log(arr)
                resolve(arr)
            }
        })
    
    })
}


module.exports = myArticleList